import { createRouter, createWebHistory } from 'vue-router';

// 引入页面和布局组件
const HomePage = () => import('./pages/HomePage.vue');
const AddDiaryPage = () => import('./pages/AddDiaryPage.vue');
const EditDiaryPage = () => import('./pages/EditDiaryPage.vue');
const LoginPage = () => import('./pages/LoginPage.vue');
const RegisterPage = () => import('./pages/RegisterPage.vue');
const NotFoundPage = () => import('./pages/NotFoundPage.vue'); // 404 页面

// 引入布局组件
import DefaultLayout from '@/layouts/DefaultLayout.vue';
import AuthLayout from '@/layouts/AuthLayout.vue';
import AboutPage from './pages/AboutPage.vue';
import TestPage from './pages/TestPage.vue';
import SettingPage from './user/SettingPage.vue';
import ProfilePage from './user/ProfilePage.vue';
import SharePage from './pages/SharePage.vue';
import PostPage from './pages/PostPage.vue';
import Myshare from './pages/Myshare.vue';
import Chatlist from './pages/Chatlist.vue';
import Chat from './pages/Chat.vue';


// 定义路由
const routes = [
  {
    path: '/',
    component: HomePage,
    meta: { layout: DefaultLayout },
  },
  {
    path: '/about',
    component: AboutPage,
    meta: { layout: DefaultLayout },
    props: true, // 允许传递 URL 参数到组件
  },
  {
    path: '/chat/:id',
    name: 'Chat',
    component: Chat,
    props: true, // 启用路由参数传递
  },
  {
    path: '/chatlist',
    component: Chatlist,
    meta: { layout: DefaultLayout },
  },
  {
    path: '/settings',
    component: SettingPage,
    name: 'SettingPage',
    meta: { layout: DefaultLayout },
  },
  {
    path: '/share',
    component: SharePage,
    name: 'SharePage',
    meta: { layout: DefaultLayout },
  },
  {
    path: '/myshare',
    component: Myshare,
    name: 'Myshare',
    meta: { layout: DefaultLayout },
  },
  {
    path: '/profile',
    component: ProfilePage,
    name: 'ProfilePage',
    meta: { layout: DefaultLayout },
  },
  {
    path: '/test',
    component: TestPage,
    meta: { layout: DefaultLayout },
  },
  {
    path: '/add',
    component: AddDiaryPage,
    meta: { layout: DefaultLayout },
  },
  {
    path: '/edit-diary/:diaryId',
    component: EditDiaryPage,
    name: 'EditDiaryPage',
    meta: { layout: DefaultLayout },
  },
  {
    path: '/login',
    component: LoginPage,
    name: 'LoginPage',
    meta: { layout: AuthLayout },
  },
  {
    path: '/register',
    component: RegisterPage,
    name: 'RegisterPage',
    meta: { layout: AuthLayout },
  },
  {
    path: '/postpage',
    component: PostPage,
    name: 'PostPage',
    meta: { layout: DefaultLayout },
  },
  {
    path: '/:catchAll(.*)', // 捕获所有未匹配的路径
    component: NotFoundPage, // 显示404页面
    meta: { layout: AuthLayout }, // 默认布局
  },
];

// 创建路由实例
const router = createRouter({
  history: createWebHistory(),
  routes,
});

export default router;
